//
//  QLViewController.m
//  Demo_QLCyclicADPLayer
//
//  Created by 闫庆龙 on 15/4/13.
//  Copyright (c) 2015年 Shrek. All rights reserved.
//

#import "QLViewController.h"

#import "QLCyclicADPlayer.h"

@interface QLViewController () <QLCyclicADPlayerDataSourceDelegate, QLCyclicADPlayerActionDelegate>
{
    __weak QLCyclicADPlayer *_cyclicAdPlayer;
    NSArray *_arrUrlStrings;
}

@end

@implementation QLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"QLCyclicADPlayer";
    
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
    
    _arrUrlStrings = @[@"http://pic3.nipic.com/20090616/1441505_172123068_2.jpg",
                       @"http://pic19.nipic.com/20120315/4758005_091854125000_2.jpg",
                       @"http://img3.3lian.com/2013/v11/41/d/61.jpg"];
    
    QLCyclicADPlayer *cyclicAdPlayer = [[QLCyclicADPlayer alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
    cyclicAdPlayer.dataSourceDelegate = self;
    cyclicAdPlayer.actionDelegate = self;
    cyclicAdPlayer.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:cyclicAdPlayer];
    _cyclicAdPlayer = cyclicAdPlayer;
}

#pragma mark - QLCyclicADPlayerDataSourceDelegate
- (NSUInteger)numberOfPagesInCyclicADPlayer:(QLCyclicADPlayer *)cyclicADPlayer {
    return _arrUrlStrings.count;
}
- (NSURL *)cyclicADPlayer:(QLCyclicADPlayer *)cyclicADPlayer UrlAtIndex:(NSUInteger)index {
    return [NSURL URLWithString:_arrUrlStrings[index]];
}

#pragma mark - QLCyclicADPlayerActionDelegate
- (void)cyclicADPlayer:(QLCyclicADPlayer *)cyclicADPlayer DidClickAtIndex:(NSUInteger)index {
    NSLog(@"%s~%@", __FUNCTION__, @(index));
}

- (void)viewWillAppear:(BOOL)animated {
//    [_cyclicAdPlayer startCyclicADPlayer];
}
- (void)viewWillDisappear:(BOOL)animated {
//    [_cyclicAdPlayer pauseCyclicADPlayer];
}

@end
